package com.llho.admin.product;

import java.util.ArrayList;
import java.util.List;

import com.llho.admin.BaseAction;
import com.llho.core.bo.CatalogBo;
import com.llho.core.bo.ProductBo;
import com.llho.core.domain.Catalog;
import com.llho.core.domain.Product;

public class ListingAction extends BaseAction {
	List<Product> products = new ArrayList<Product>();
	private Long idCatalog;

	ProductBo productBo;

	// DI via Spring
	public void setProductBo(ProductBo productBo) {
		this.productBo = productBo;
	}

	CatalogBo catalogBo;

	// DI via Spring
	public void setCatalogBo(CatalogBo catalogBo) {
		this.catalogBo = catalogBo;
	}

	public String execute() {
		products = productBo.getAll();
		System.out.println(products.size());
		return "success";
	}

	public String filter() {
		if (idCatalog == 0) {
			products = productBo.getAll();
		} else {
			Catalog catalog = catalogBo.getById(idCatalog);
			products = productBo.getByCatalog(catalog);
		}
		return "success";
	}

	public List<Product> getProducts() {
		return products;
	}

	public void setProducts(List<Product> products) {
		this.products = products;
	}

	public Long getIdCatalog() {
		return idCatalog;
	}

	public void setIdCatalog(Long idCatalog) {
		this.idCatalog = idCatalog;
	}
}
